/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Ondrej
 */
@Entity
@Table(name = "person")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p"),
    @NamedQuery(name = "Person.findById", query = "SELECT p FROM Person p WHERE p.id = :id"),
    @NamedQuery(name = "Person.findByFirstName", query = "SELECT p FROM Person p WHERE p.firstName = :firstName"),
    @NamedQuery(name = "Person.findByLastName", query = "SELECT p FROM Person p WHERE p.lastName = :lastName"),
    @NamedQuery(name = "Person.findByBirthday", query = "SELECT p FROM Person p WHERE p.birthday = :birthday"),
    @NamedQuery(name = "Person.findByAddress", query = "SELECT p FROM Person p WHERE p.address = :address"),
    @NamedQuery(name = "Person.findByEmail", query = "SELECT p FROM Person p WHERE p.email = :email"),
    @NamedQuery(name = "Person.findByTelephoneNr", query = "SELECT p FROM Person p WHERE p.telephoneNr = :telephoneNr"),
    @NamedQuery(name = "Person.findByMobileNr", query = "SELECT p FROM Person p WHERE p.mobileNr = :mobileNr"),
    @NamedQuery(name = "Person.findByActiveFrom", query = "SELECT p FROM Person p WHERE p.activeFrom = :activeFrom"),
    @NamedQuery(name = "Person.findByActiveTo", query = "SELECT p FROM Person p WHERE p.activeTo = :activeTo")})
public class Person implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Size(max = 20)
    @Column(name = "first_name")
    private String firstName;
    @Size(max = 20)
    @Column(name = "last_name")
    private String lastName;
    @Column(name = "birthday")
    private Integer birthday;
    @Size(max = 50)
    @Column(name = "address")
    private String address;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Size(max = 30)
    @Column(name = "email")
    private String email;
    @Size(max = 20)
    @Column(name = "telephone_nr")
    private String telephoneNr;
    @Size(max = 20)
    @Column(name = "mobile_nr")
    private String mobileNr;
    @Column(name = "active_from")
    private Integer activeFrom;
    @Column(name = "active_to")
    private Integer activeTo;
    @OneToMany(mappedBy = "pERSONid")
    private Collection<Users> usersCollection;
    @JoinColumn(name = "BANK_ACCOUNT_id", referencedColumnName = "id")
    @ManyToOne
    private BankAccount bANKACCOUNTid;
    @OneToMany(mappedBy = "pERSONid")
    private Collection<FileShare> fileShareCollection;
    @OneToMany(mappedBy = "pERSONid")
    private Collection<Contact> contactCollection;
    @OneToMany(mappedBy = "pERSONid")
    private Collection<Plotting> plottingCollection;
    @OneToMany(mappedBy = "pERSONid")
    private Collection<Employee> employeeCollection;

    public Person() {
    }

    public Person(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Integer getBirthday() {
        return birthday;
    }

    public void setBirthday(Integer birthday) {
        this.birthday = birthday;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getTelephoneNr() {
        return telephoneNr;
    }

    public void setTelephoneNr(String telephoneNr) {
        this.telephoneNr = telephoneNr;
    }

    public String getMobileNr() {
        return mobileNr;
    }

    public void setMobileNr(String mobileNr) {
        this.mobileNr = mobileNr;
    }

    public Integer getActiveFrom() {
        return activeFrom;
    }

    public void setActiveFrom(Integer activeFrom) {
        this.activeFrom = activeFrom;
    }

    public Integer getActiveTo() {
        return activeTo;
    }

    public void setActiveTo(Integer activeTo) {
        this.activeTo = activeTo;
    }

    @XmlTransient
    public Collection<Users> getUsersCollection() {
        return usersCollection;
    }

    public void setUsersCollection(Collection<Users> usersCollection) {
        this.usersCollection = usersCollection;
    }

    public BankAccount getBANKACCOUNTid() {
        return bANKACCOUNTid;
    }

    public void setBANKACCOUNTid(BankAccount bANKACCOUNTid) {
        this.bANKACCOUNTid = bANKACCOUNTid;
    }

    @XmlTransient
    public Collection<FileShare> getFileShareCollection() {
        return fileShareCollection;
    }

    public void setFileShareCollection(Collection<FileShare> fileShareCollection) {
        this.fileShareCollection = fileShareCollection;
    }

    @XmlTransient
    public Collection<Contact> getContactCollection() {
        return contactCollection;
    }

    public void setContactCollection(Collection<Contact> contactCollection) {
        this.contactCollection = contactCollection;
    }

    @XmlTransient
    public Collection<Plotting> getPlottingCollection() {
        return plottingCollection;
    }

    public void setPlottingCollection(Collection<Plotting> plottingCollection) {
        this.plottingCollection = plottingCollection;
    }

    @XmlTransient
    public Collection<Employee> getEmployeeCollection() {
        return employeeCollection;
    }

    public void setEmployeeCollection(Collection<Employee> employeeCollection) {
        this.employeeCollection = employeeCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Person)) {
            return false;
        }
        Person other = (Person) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.entities.Person[ id=" + id + " ]";
    }
    
}
